package core;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class ReaderThread implements Runnable {

	private InputStream in;
	private boolean isRunning;
	public List<String> queues;

	public ReaderThread(InputStream in) {
		this.in = in;
		this.queues = new ArrayList<String>();
		this.isRunning = true;
		new Thread(this).start();
	}

	@Override
	public void run() {
		while (isRunning) {
			try {
				int lenght = in.available();
                if (lenght == 0) {
                	continue;
                }
                byte[] data = new byte[lenght];
                int count = in.read(data);
                while (count < lenght) {
                    count += in.read(data, count, lenght - count);
                }
                String message = new String(data);
                System.out.println(message);
				if (message != null && message.length() > 0) {
					queues.add(message);
				}
			} catch (Exception ex) {
				System.out.println("Reader Thread: " + ex.getMessage());
			}
		}
	}

}
